package saas.consumer.service.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author guan.xin
 * @title TestAspect
 * @description
 * @create 2022-04-14 11:12
 * @since JDK8
 */
@Aspect
@Component
public class TestAspect {

    private final static AtomicBoolean condition = new AtomicBoolean(false);

    private Random random = new Random();

    @Pointcut("execution(public * saas.consumer.service.biz.BaseBizService+.testAop()) && target(saas.consumer.service.biz.BizService)")
    public void pointcut() {
    }

    @Pointcut("execution(public * saas.consumer.service.biz.BaseBizService+.testAop2(..)) && target(saas.consumer.service.biz.BizService)")
    public void pointcut2() {
    }

    @Around(value = "pointcut() || pointcut2()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        if (random.nextBoolean()) {
            return pjp.proceed();
        } else {
            return "replace test aop";
        }
    }
}
